using System;
using System.Collections.Generic;
using System.Text;

namespace Wrath.Xml.Objects
{
    public class ControlStateFrame : IElementContainer
    {
        private StateFrameDefinition hover;
        private StateFrameDefinition dropHighlight;
        private StateFrameDefinition dropHover;

        public ControlStateFrame(Element element)
        {
            sourceElement = element;

            Element subElement = element.FindFirstElement("hover", false);
            if (subElement != null)
            {
                hover = new StateFrameDefinition("hover", subElement);
            }

            subElement = element.FindFirstElement("drophighlight", false);
            if (subElement != null)
            {
                dropHighlight = new StateFrameDefinition("drophighlight", subElement);
            }

            subElement = element.FindFirstElement("drophover", false);
            if (subElement != null)
            {
                dropHover = new StateFrameDefinition("drophover", subElement);
            }
        }

        #region IElementContainer Members

        private Element sourceElement;
        public Element SourceElement
        {
            get { return sourceElement; }
        }

        public void Commit()
        {
            sourceElement = new Element("stateframe");

            if (hover != null)
            {
                hover.Commit();
                sourceElement.ChildElements.Add(hover.SourceElement);
            }

            if (dropHighlight != null)
            {
                dropHighlight.Commit();
                sourceElement.ChildElements.Add(dropHighlight.SourceElement);
            }

            if (dropHover != null)
            {
                dropHover.Commit();
                sourceElement.ChildElements.Add(dropHover.SourceElement);
            }

        }

        #endregion
    }
}
